﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;

namespace WorkNodeFramework
{
    public class Delete:Query<Delete>, IExecuteCommand
    {
        public Delete()
        { }

        public Delete(DataProvider provider)
            : this()
        {
            base.Provider = provider;
        }

        public string BuildDeleteQueryStatement(ParameterIndexCollection parameters)
        {
            return Provider.BuildDeleteQueryStatement(this, parameters);
        }

        public int Execute()
        {
            ParameterIndexCollection parIndexes = new ParameterIndexCollection();
            string cmdText = BuildDeleteQueryStatement(parIndexes);
            return Provider.ExecuteNonQuery(cmdText, parIndexes.ToDbParameters(Provider));
        }

        #region IExecuteCommand Members

        public ExecuteCommand BuildExecuteCommand()
        {
            ParameterIndexCollection parIndexes = new ParameterIndexCollection();
            string cmdText = BuildDeleteQueryStatement(parIndexes);
            return new ExecuteCommand(cmdText, parIndexes.ToDbParameters(Provider));
        }

        #endregion
    }
}
